<?php

namespace system\core;

Abstract class abstractAttribute
{

	private $key;
	private $value;
	private $separator;
	private $delimiter;
	private $attributeEnd;
	private $case;

	function __construct($key="", $value="")
	{
		$this->setKey($key);
		$this->setValue($value);
	}

	function setKey($key)
	{
		$this->key = $key;
	}

	function setValue($value)
	{
		$this->value = $value;
	}

	function getKey()
	{
		$key = $this->key;
		$key = $this->case_transform($key);
		$this->nocase();
		return $key;
	}

	function getValue()
	{
		$value = $this->value;
		$value = $this->case_transform($value);
		$this->nocase();
		return $value;
	}

	protected function setSeparator($string)
	{
		$this->separator = $string;
	}

	protected function getSeparator()
	{
		return $this->separator;
	}

	protected function setDelimiter($delimiter)
	{
		$this->delimiter = $delimiter;
	}

	protected function getDelimiter()
	{
		return $this->delimiter;
	}

	protected function setAttributeEnd($string)
	{
		$this->attributeEnd = $string;
	}

	protected function getAttributeEnd()
	{
		return $this->attributeEnd;
	}

	function __toString()
	{
		return $this->getKey().
						$this->getSeparator().
						$this->getDelimiter().
						$this->getValue().
						$this->getDelimiter().
						$this->getAttributeEnd();
	}

	private function getCase()
	{
		return $this->case;
	}

	function nocase()
	{
		$this->case = false;
	}

	function lowercase()
	{
		$this->case = MB_CASE_LOWER;
		return $this;
	}

	function uppercase()
	{
		$this->case = MB_CASE_UPPER;
		return $this;
	}

	private function case_transform($value)
	{
		if( $this->getCase() === false )
		{
			return $value;
		}

		if( function_exists("\mb_convert_case") )
		{
			$value = \mb_convert_case($value, $this->getCase());
		}
		else
		{
			switch ($this->getCase())
			{
				case MB_CASE_LOWER:
					$value = strtolower($value);
					break;
				case MB_CASE_UPPER:
					$value = strtoupper($value);
					break;
			}
		}
		return $value;
	}

}

?>
